<#-- 用户注册页面一 -->
<#include "/WEB-INF/default/fragment/nonev.ftl">
<div class="container">
    <form class="from user-login" action="${request.contextPath}/reg-info.action" method="post">
        <fieldset>
            <div id="reg_mas" class="clearfix">
                <div class="reg_info">
                    <img src="./assets/image/register_info01.png">
                </div>
                <div class="reg_from">
                    <img src="./assets/image/logo.png">
                    <div class="input">
                        <input type="text" name="user.email" placeholder="邮箱">
                        <div class="remail"></div>
                        <input type="password" name="user.password" placeholder="密码">
                        <div class="rpassword"></div>
                        <input type="password" name="user.agpwd" placeholder="确认密码">
                        <div class="ragpwd"></div>
                    </div>
                    <button type="submit" id="reg_next_btn">下一步</button>
                </div>
            </div>
        </fieldset>
    </form>
    <script type="text/javascript">
        $(function(){
           /* $(document).on('blur', 'input[name=\'user.email\']', function(event) {
                var d = $('input[name="user.email"]').val();
                d += '&struts.enableJSONValidation=true';
                $.post('${request.contextPath}/reg-checkEmail.action', d, function(json, textStatus) {
                  //optional stuff to do after success
                  if (json!="") {
                    for(var i in json['fieldErrors']){
                        if(json['fieldErrors']['user.email']==null){
                            $r.html("<img src='./assets/image/false.png'>");
                        }
                        if(i!=""){
                            var $r = $('.r'+i+'');
                            $r.addClass('error');
                            $r.html("<img src='./assets/image/false.png'><span>"+i+"</span>");
                        }
                    }
                  }
                });
            });*/
            $('input').focus(function(event) {
                $(this).next('div').removeClass('error');
                $(this).next('div').html("");
            });
            $('input[name=\'user.password\']').blur(function(event) {
                $.ajax({
                  url: '${request.contextPath}/reg-infopwd.action',
                  type: 'POST',
                  dataType: 'text',
                  data: {},
                  complete: function(xhr, textStatus) {
                    //called when complete
                  },
                  success: function(data, textStatus, xhr) {
                    if(data==""){
                        return false;
                    }
                    var da = JSON.parse(data);
                    if (da['fieldErrors']) {
                        $('.rpassword').html("<img src='./assets/image/success.png'>");
                    }
                    for(var i in da['fieldErrors']){
                        $('.rpassword').addClass('error');
                        $('.rpassword').html("<img src='./assets/image/false.png'><span>"+da['fieldErrors'][i]+"</span>");
                    }
                  },
                  error: function(xhr, textStatus, errorThrown) {
                    //called when there is an error
                  }
                });
                return false;
            });
            $('input[name=\'user.agpwd\']').blur(function(event) {
                $.ajax({
                  url: '${request.contextPath}/reg-infopwd.action',
                  type: 'POST',
                  dataType: 'text',
                  data: {},
                  complete: function(xhr, textStatus) {
                    //called when complete
                  },
                  success: function(data, textStatus, xhr) {
                    if(data==""){
                        $('.ragpwd').html("<img src='./assets/image/success.png'>");
                        return false;
                    }
                    var da = JSON.parse(data);
                    for(var i in da['fieldErrors']){
                        $('.ragpwd').addClass('error');
                        $('.ragpwd').html("<img src='./assets/image/false.png'><span>"+da['fieldErrors'][i]+"</span>");
                    }
                  },
                  error: function(xhr, textStatus, errorThrown) {
                    //called when there is an error
                  }
                });
                return false;
            });
            $('input[name=\'user.email\']').blur(function(event) {
                $.ajax({
                  url: '${request.contextPath}/reg-checkEmail.action',
                  type: 'POST',
                  dataType: 'text',
                  data: {'user.email': $('input[name="user.email"]').val(),'struts.enableJSONValidation':true},
                  complete: function(xhr, textStatus) {
                    //called when complete
                  },
                  success: function(data, textStatus, xhr) {
                    if (data=="") {
                        $('.remail').html("<img src='./assets/image/success.png'>");
                        return false;
                    }
                    var da = JSON.parse(data);
                    for(var i in da){
                        if (i=='remail') {
                            $('.remail').addClass('error');
                            $('.remail').html("<img src='./assets/image/false.png'><span>"+da[i]+"</span>");
                        }else {
                            var info = da[i]['user.email'];
                            $('.remail').addClass('error');
                            $('.remail').html("<img src='./assets/image/false.png'><span>"+info+"</span>");
                        }
                    }
                  },
                  error: function(xhr, textStatus, errorThrown) {
                    //called when there is an error
                  }
                });
                return false;
            });
            $('.from').bind('submit', function(event) {
                $('#login_btn').addClass('loding');
                $('#login_btn').html('<img src="./assets/image/loding.gif">');
                var data = $('.user-login').serialize();
                data += '&struts.enableJSONValidation=true';
                $.getJSON('${request.contextPath}/reg-info.action', {data}, function(json, textStatus) {
                    var da = json;
                });
                return false;
            });
        });
    </script>
</div>
<#include "/WEB-INF/default/fragment/footer.ftl">